home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / tc_tsr10.zip / TSR_LIST.C < prev    next >
Text File  |  1991-06-14  |  7KB  |  139 lines

  1. /*--------------------------------------------------------------------------*
  2.  | Author:                                                                  |
  3.  | Sherif El-Kassas        .       :.                                       |
  4.  | EB dept           \_____o__/ __________                                  |
  5.  | Eindhoven U of Tec       .. /                                            |
  6.  | The Netherlands            /             Email: elkassas@eb.ele.tue.nl   |
  7.  *--------------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------------*
  10.  | The author shall not be liable to the user for any direct, indirect      |
  11.  | or consequential loss arising from the use of, or inability to use,      |
  12.  | any program or file howsoever caused.  No warranty is given that the     |
  13.  | programs will work under all circumstances.                              |
  14.  *--------------------------------------------------------------------------*/
  15.  
  16. /*--------------------------------------------------------------------------*
  17.  | TSR_LIST.C                                                               |
  18.  |   TSR_LIST prints a list of memory resident programs.                    |
  19.  |   TSR_LIST is supplied as is with no warranty, expressed or implied.     |
  20.  |   It is not copyrighted, either.                                         |
  21.  |   Compile with: TCC tsr_list.c                                           |
  22.  *--------------------------------------------------------------------------*/
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <dos.h>
  27.  
  28. /*
  29.  |
  30.  |  Memory control block (arena header) structure:
  31.  |
  32.  |            00  +---------------------------------+
  33.  |                | ID byte 'M' or 'Z'              |
  34.  |            01  +---------------------------------+
  35.  |                | block owner (PSP of owner)      |
  36.  |            03  +---------------------------------+
  37.  |                | memory block size in paragraphs |
  38.  |            05  +---------------------------------+
  39.  |                | reserved                        |
  40.  |            0F  +---------------------------------+
  41.  |
  42.  |
  43.  */
  44.  
  45. /*--------------------------------------------------------------------------*
  46.  |                         MACRO DEFINITIONS                                |
  47.  *--------------------------------------------------------------------------*/
  48.  
  49. #define FAR_WORD(seg, ofs)         (* (unsigned far *) MK_FP(seg, ofs) )
  50.  
  51. #define FAR_CHAR(seg, ofs)         (* (char far *) MK_FP(seg, ofs) )
  52.  
  53. #define IS_ARENA_HEADER(seg)       ( FAR_CHAR(seg, 0) == 'M' )
  54.  
  55. #define IS_PSP_ARENA_HEADER(seg)   ( FAR_WORD(seg, 1) == ((seg)+1) )
  56.  
  57. #define IS_FIRST_ARENA_HEADER(seg) ( IS_ARENA_HEADER( seg )  &&  \
  58.                                      IS_PSP_ARENA_HEADER( seg ) )
  59.  
  60. #define IS_LAST_ARENA_HEADER(seg)  ( FAR_CHAR(seg, 0) == 'Z')
  61.  
  62. #define ARENA_SIZE(seg)            ( FAR_WORD(seg, 3) )
  63.  
  64. #define NEXT_ARENA_HEADER(seg)     ( ARENA_SIZE(seg) + (seg) + 1 )
  65.  
  66.  
  67. /*--------------------------------------------------------------------------*
  68.  | print_program_name                                                       |
  69.  |   get program name from environment space (if possible) and print it     |
  70.  *--------------------------------------------------------------------------*/
  71.  
  72. void print_program_name(register unsigned psp){
  73.   char     far      *env_ptr;      /* far pointer to environment space      */
  74.   register unsigned env_owner;     /* actual owner's psp                    */
  75.  
  76.   env_owner = FAR_WORD( FAR_WORD(psp, 0x2c) - 1, 1 ); /* get actual owner's */
  77.                                                     /* psp from environment */
  78.   if ( (env_owner == psp) && (_osmajor >= 3) ){
  79.     env_ptr = MK_FP( FAR_WORD(psp, 0x2c), 0 ); /* point to environment      */
  80.     while(* (int far *) env_ptr++) ;          /* scan to end of environment */
  81.     env_ptr += 3;                    /* jump over 'number of strings' field */
  82.     printf("%Fs", env_ptr);              /* print far string (program name) */
  83.   }/* if */
  84.   else printf("(unknown program name)");
  85. }/* print_program_name */
  86.  
  87.  
  88. /*--------------------------------------------------------------------------*
  89.  | print_used_ints                                                          |
  90.  |   print interrupts that point to the current psp block                   |
  91.  *--------------------------------------------------------------------------*/
  92.  
  93. void print_used_ints(register unsigned psp){
  94.   void huge *begin, huge *end; /* huge pointers to block beginning and end  */
  95.   void huge * huge * intr_list = 0L; /* pointer to interrupt table          */
  96.   register  int i;
  97.  
  98.   begin = MK_FP( psp, 0 );                      /* point to block beginning */
  99.   end   = MK_FP( NEXT_ARENA_HEADER( psp-1 ), 0 ); /* point to block end     */
  100.  
  101.   printf(" ( ");
  102.   for (i=0; i <= 0xFF; i++){                      /* if an interrupt vector */
  103.     if ( *intr_list > begin && *intr_list < end ) /* points to an address   */
  104.       printf("%X ", i);                           /* between begin and end  */
  105.     intr_list++;                                  /* print the interrupt No.*/
  106.   }/* for */
  107.   printf(" )\n");
  108. }/* print_used_ints */
  109.  
  110.  
  111. /*--------------------------------------------------------------------------*
  112.  | main                                                                     |
  113.  |   find first arena header, then print loaded program names (if any)      |
  114.  *--------------------------------------------------------------------------*/
  115.  
  116. main(){
  117.   register unsigned seg;
  118.   extern   void     _restorezero(void);
  119.  
  120.   _restorezero(); /* restore interrupt vectors 0, 4, 5, and 6           */
  121.  
  122.  
  123.   /* scan memory until a memory control block (arena header) is found   */
  124.   for ( seg = 0; ! IS_FIRST_ARENA_HEADER( seg ); seg++ );
  125.  
  126.   seg = NEXT_ARENA_HEADER(seg); /* skip the first block (command.com !) */
  127.  
  128.   /* scan memory until the last memory block is found                   */
  129.   while ( ! IS_LAST_ARENA_HEADER( seg ) ){
  130.     if ( IS_PSP_ARENA_HEADER( seg ) && (_psp != seg+1) ){  /* if seg is */
  131.       print_program_name(seg+1);/* a PSP block and it's not the current */
  132.       print_used_ints(seg+1);   /* program (TSR_LIST.EXE) then print    */
  133.                                 /* program name and used interrupts.    */
  134.     }/* if */
  135.     seg = NEXT_ARENA_HEADER( seg );/* point to next memory control block*/
  136.   }/* while */
  137. }/* main */
  138.  
  139.